home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 10 / AACD 10.iso / AACD / Resources / Online / Term / Extras / Source / gtlayout-source.lha / LTP_Draw.c < prev    next >
C/C++ Source or Header  |  1996-10-11  |  6KB  |  313 lines

  1. /*
  2. **    GadTools layout toolkit
  3. **
  4. **    Copyright © 1993-1996 by Olaf `Olsen' Barthel
  5. **        Freely distributable.
  6. **
  7. **    :ts=4
  8. */
  9.  
  10. #ifndef _GTLAYOUT_GLOBAL_H
  11. #include "gtlayout_global.h"
  12. #endif
  13.  
  14.  
  15. /*****************************************************************************/
  16.  
  17.  
  18. VOID
  19. LTP_ResetRenderInfo(struct RastPort *RPort)
  20. {
  21.     SetAfPt(RPort,NULL,0);
  22.     SetDrPt(RPort,0xFFFF);
  23.     SetWrMsk(RPort,0xFF);
  24. }
  25.  
  26.  
  27. /*****************************************************************************/
  28.  
  29.  
  30. VOID
  31. LTP_GhostBox(struct RastPort *RPort,LONG Left,LONG Top,LONG Width,LONG Height,UWORD Pen)
  32. {
  33.     STATIC UWORD Ghosting[2] = { 0x4444,0x1111 };
  34.  
  35.     LTP_SetPens(RPort,Pen,0,JAM1);
  36.  
  37.     SetAfPt(RPort,Ghosting,1);
  38.     LTP_FillBox(RPort,Left,Top,Width,Height);
  39.     SetAfPt(RPort,NULL,0);
  40. }
  41.  
  42.  
  43. /*****************************************************************************/
  44.  
  45.  
  46. VOID
  47. LTP_EraseBox(struct RastPort *rp,LONG left,LONG top,LONG width,LONG height)
  48. {
  49.     if(width > 0 && height > 0)
  50.         EraseRect(rp,left,top,left + width - 1,top + height - 1);
  51. }
  52.  
  53.  
  54. /*****************************************************************************/
  55.  
  56.  
  57. VOID
  58. LTP_FillBox(struct RastPort *rp,LONG left,LONG top,LONG width,LONG height)
  59. {
  60.     if(width > 0 && height > 0)
  61.         RectFill(rp,left,top,left + width - 1,top + height - 1);
  62. }
  63.  
  64.  
  65. /*****************************************************************************/
  66.  
  67.  
  68. VOID
  69. LTP_DrawLine(struct RastPort *rp,LONG x0,LONG y0,LONG x1,LONG y1)
  70. {
  71.         // Recent studies reveal that for horizontal and
  72.         // vertical lines RectFill() is in most cases faster
  73.         // than Move()..Draw(). This only works if we don't
  74.         // rely upon rp->cp_x/cp_y being updated by Draw().
  75.         // As of v26.11 the library no longer does this.
  76.  
  77.     if(x0 == x1 || y0 == y1)
  78.     {
  79.             // If there only were a `C' primitive to swap
  80.             // two variables...
  81.  
  82.         if(x0 > x1)
  83.             x0 ^= x1, x1 ^= x0, x0 ^= x1;
  84.  
  85.         if(y0 > y1)
  86.             y0 ^= y1, y1 ^= y0, y0 ^= y1;
  87.  
  88.         RectFill(rp,x0,y0,x1,y1);
  89.     }
  90.     else
  91.     {
  92.         Move(rp,x0,y0);
  93.         Draw(rp,x1,y1);
  94.     }
  95. }
  96.  
  97. VOID
  98. LTP_PolyDraw(struct RastPort *rp,LONG totalPairs,LONG left,LONG top,...)
  99. {
  100.     LONG x0,y0,x1,y1;
  101.     LONG *pairs;
  102.     va_list args;
  103.  
  104.     x0 = left;
  105.     y0 = top;
  106.  
  107.     va_start(args,top);
  108.  
  109.     pairs = (LONG *)args;
  110.  
  111.     while(--totalPairs > 0)
  112.     {
  113.         x1 = *pairs++;
  114.         y1 = *pairs++;
  115.  
  116.         LTP_DrawLine(rp,x0,y0,x1,y1);
  117.  
  118.         x0 = x1;
  119.         y0 = y1;
  120.     }
  121.  
  122.     va_end(args);
  123. }
  124.  
  125.  
  126. /*****************************************************************************/
  127.  
  128.  
  129. VOID
  130. LTP_RenderBevel(struct RastPort *rp,UWORD *pens,LONG left,LONG top,LONG width,LONG height,BOOL recessed,WORD thickness)
  131. {
  132.     LONG pen1,pen2;
  133.  
  134.     if(recessed)
  135.     {
  136.         pen1 = SHADOWPEN;
  137.         pen2 = SHINEPEN;
  138.     }
  139.     else
  140.     {
  141.         pen1 = SHINEPEN;
  142.         pen2 = SHADOWPEN;
  143.     }
  144.  
  145.     LTP_SetAPen(rp,pens[pen1]);
  146.     LTP_PolyDraw(rp,3,
  147.         left,top + height - 1,
  148.         left,top,
  149.         left + width - 2,top);
  150.  
  151.     if(thickness > 1)
  152.     {
  153.         LTP_DrawLine(rp,left + 1,top + 1,left + 1,top + height - 2);
  154.  
  155.         if(thickness > 2)
  156.         {
  157.             LTP_PolyDraw(rp,3,
  158.                 left + 2,top + height - 3,
  159.                 left + 2,top + 1,
  160.                 left + width - 3,top + 1);
  161.         }
  162.     }
  163.  
  164.     LTP_SetAPen(rp,pens[pen2]);
  165.     LTP_PolyDraw(rp,3,
  166.         left + width - 1,top,
  167.         left + width - 1,top + height - 1,
  168.         left + 1,top + height - 1);
  169.  
  170.     if(thickness > 1)
  171.     {
  172.         LTP_DrawLine(rp,left + width - 2,top + height - 2,left + width - 2,top + 1);
  173.  
  174.         if(thickness > 2)
  175.         {
  176.             LTP_PolyDraw(rp,3,
  177.                 left + width - 3,top + 2,
  178.                 left + width - 3,top + height - 2,
  179.                 left + 2,top + height - 2);
  180.         }
  181.     }
  182. }
  183.  
  184. VOID
  185. LTP_DrawBevel(LayoutHandle *handle,LONG left,LONG top,LONG width,LONG height)
  186. {
  187.     LTP_RenderBevel(&handle->RPort,handle->DrawInfo->dri_Pens,left,top,width,height,TRUE,2);
  188. }
  189.  
  190. VOID
  191. LTP_DrawBevelBox(LayoutHandle *handle,ObjectNode *node)
  192. {
  193.     LTP_DrawBevel(handle,node->Left,node->Top,node->Width,node->Height);
  194. }
  195.  
  196.  
  197. /*****************************************************************************/
  198.  
  199.  
  200. VOID
  201. LTP_PrintText(struct RastPort *rp,STRPTR text,LONG textLen,LONG x,LONG y)
  202. {
  203.     Move(rp,x,y + rp->TxBaseline);
  204.     Text(rp,text,textLen);
  205. }
  206.  
  207.  
  208. /*****************************************************************************/
  209.  
  210.  
  211. VOID
  212. LTP_DrawGroove(LayoutHandle *handle,LONG left,LONG top,LONG width,LONG height,LONG from,LONG to)
  213. {
  214.     struct RastPort *rp = &handle->RPort;
  215.     LONG x,y;
  216.  
  217.     LTP_SetAPen(rp,handle->ShadowPen);
  218.  
  219.     LTP_PolyDraw(rp,5,
  220.         left + 1,top + 1,
  221.         left + 1,top + height - 2,
  222.         left,top + height - 1,
  223.         left,top,
  224.         from - 2,top);
  225.  
  226.     if(from < to)
  227.     {
  228.         x = to + 1;
  229.         y = top + 1;
  230.     }
  231.     else
  232.     {
  233.         x = from - 1;
  234.         y = top;
  235.     }
  236.  
  237.     LTP_PolyDraw(rp,6,
  238.         x,y,
  239.         to + 1,top,
  240.         left + width - 2,top,
  241.         left + width - 3,top + 1,
  242.         left + width - 3,top + height - 2,
  243.         left + 3,top + height - 2);
  244.  
  245.     LTP_DrawLine(rp,
  246.         left + width - 4,top + 2,
  247.         left + width - 4,top + height - 3);
  248.  
  249.     LTP_SetAPen(rp,handle->ShinePen);
  250.  
  251.     if(from < to)
  252.     {
  253.         x = from - 1;
  254.         y = top;
  255.     }
  256.     else
  257.     {
  258.         x = from + 2;
  259.         y = top + 1;
  260.     }
  261.  
  262.     LTP_PolyDraw(rp,9,
  263.         left + width - 2,top + height - 2,
  264.         left + width - 2,top + 1,
  265.         left + width - 1,top,
  266.         left + width - 1,top + height - 1,
  267.         left + 1,top + height - 1,
  268.         left + 2,top + height - 2,
  269.         left + 2,top + 1,
  270.         from - 1,top + 1,
  271.         x,y);
  272.  
  273.     LTP_DrawLine(rp,
  274.         to + 2,top + 1,
  275.         left + width - 4,top + 1);
  276.  
  277.     LTP_DrawLine(rp,
  278.         left + 3,top + 2,
  279.         left + 3,top + height - 3);
  280. }
  281.  
  282.  
  283. /*****************************************************************************/
  284.  
  285.  
  286. VOID
  287. LTP_DrawGroupLabel(LayoutHandle *handle,ObjectNode *node)
  288. {
  289.     struct RastPort *rp;
  290.     LONG left,top,height;
  291.  
  292.     left = node->Left + (node->Width - node->LabelWidth) / 2;
  293.     rp = &handle->RPort;
  294.  
  295.     if(node->Label)
  296.     {
  297.         LONG glyphHeight = handle->GlyphHeight;
  298.  
  299.         top = node->Top + glyphHeight / 2;
  300.         height = node->Height - (glyphHeight + handle->InterHeight) / 2;
  301.  
  302.         LTP_SetPens(rp,handle->DrawInfo->dri_Pens[HIGHLIGHTTEXTPEN],0,JAM1);
  303.         LTP_PrintText(rp,node->Label,strlen(node->Label),left + handle->GlyphWidth,node->Top);
  304.     }
  305.     else
  306.     {
  307.         top = node->Top;
  308.         height = node->Height - handle->InterHeight / 2;
  309.     }
  310.  
  311.     LTP_DrawGroove(handle,node->Left + handle->GlyphWidth / 2,top,node->Width - handle->GlyphWidth,height,left,left + node->LabelWidth - 1);
  312. }
  313.